<template>
	<view>
		<view class="head-block">
			<view class="head">
				<!-- 80rpx -->
				<view class="order-search">
					<image src="/static/images/search002.png" mode="widthFix" class="img"></image>
					<input type="text" v-model="order" class="inp" placeholder="快递单号查询" placeholder-class="inp-place">
				</view>
				
				<view class="search-time">
					<view class="search-time-item" @click="searchTimeChange(index)" :class="{active: searchTimeSelectIndex == index}" v-for="(item, index) in searchTimeList" :key="index">{{item.title}}</view>
				</view>
				
				<!-- 80rpx -->
				<view class="other-condition">				
					<view class="product-search">
						<input type="text" v-model="title" placeholder="搜索品名" placeholder-class="inp-class" class="inp">
					</view>
					
					<view class="addressee-search">
						<input type="text" v-model="surname" placeholder="搜索收件人" placeholder-class="inp-class" class="inp">
					</view>
				</view>
				
				<view class="summary-info">
					<view class="summary-item">
						<text class="txt">快递个数：</text>
						<text class="txt active">{{sumGoodSize}}</text>
					</view>
					
					<view class="summary-item">
						<text class="txt">快递重量：</text>
						<text class="txt active">{{sumWeight}}</text>
					</view>
					
					<view class="summary-item">
						<text class="txt">收费重：</text>
						<text class="txt active">{{logisticsCount}}</text>
					</view>
				</view>
			</view>
		</view>
	
		<view class="order-list">
			<view class="order-item" v-for="(item, index) in list" :key="index">
				<view class="order-head flex flex-align-center flex-space-between">
					<text class="txt color-09f font-24">{{item.delivery_site_name || ''}}</text>
					<text class="txt color-09f font-24">{{item.channel_name || ''}}</text>
					<text class="txt color-09f font-24">{{item.good_type || ''}}</text>
				</view>
				<view class="order-body">
					<view class="time-order">
						<view class="time item">
							<text class="txt">出仓时间：</text>
							<text class="txt">{{item.storehousetime || ''}}</text>
						</view>
						
						<view class="time item">
							<text class="txt">快递单号：</text>
							<view class="copy">
								<text class="txt">{{item.logistics_number || ''}}</text>
								<image @click.stop="copyData(item.logistics_number)" src="/static/images/copy.png" mode="widthFix" class="img"></image>
							</view>
						</view>
					</view>
					
					<view class="time-order express-dynamic">
						<view class="time item">
							<text class="txt">货态时间：</text>
							<text class="txt">{{item.record_action_time || ''}}</text>
						</view>
						
						<view class="time item dynamic-txt">
							<text class="txt">{{item.record_action || ''}}</text>
						</view>
					</view>
				
					<view class="order-goods">
						<view class="goods-image-title">
							<view class="image">
								<image :src="item.good_pic[0]" mode="aspectFill" class="img"></image>
							</view>
							<view class="title">
								<text class="txt">{{item.good_quantity[0] || ''}}</text>
							</view>
						</view>
						<view class="acting-num">
							<view class="num-item active">
								<view class="num-item-title">代垫：</view>
								<view class="num-item-val">{{item.acting_mat_fee || 0}}</view>
							</view>
							<view class="num-item">
								<view class="num-item-title">数量：</view>
								<view class="num-item-val">{{item.good_number || 0}}</view>
							</view>
							<view class="num-item">
								<view class="num-item-title">件数：</view>
								<view class="num-item-val">{{item.good_size || 0}}</view>
							</view>
						</view>
					</view>
					
					<view class="order-type-pack">
						<view class="type">{{item.warehouse_items_type_name || ''}}</view>
						<view class="pack">收件人：{{item.pick_name || ''}}</view>
					</view>
					
					<view class="order-other-info">
						<view class="other-info-item goods-other-info">
							<view class="goods-other-info-line">
								<view class="goods-other-info-item">
									<text class="title">重量：</text>
									<text class="txt">{{item.good_weight}}</text>
								</view>
								<view class="goods-other-info-item">
									<text class="title">尺寸：</text>
									<text class="txt">{{item.good_long}}*{{item.good_wide}}*{{item.good_high}}</text>
								</view>
							</view>
							<view class="goods-other-info-line">
								<view class="goods-other-info-item">
									<text class="title">材积：</text>
									<text class="txt">{{item.volume_air}}</text>
								</view>
								<view class="goods-other-info-item">
									<text class="title">体积重：</text>
									<text class="txt">{{item.volume_sea}}</text>
								</view>
							</view>
						</view>
						<view class="other-info-item other-order-num">
							<view class="other-order-num-item">
								<text class="title">查件单号：</text>
								<view class="value">
									<text class="txt">{{item.logistics_sn}}</text>
									<image @click.stop="copyData(item.logistics_sn)" src="/static/images/copy.png" mode="widthFix" class="img"></image>
								</view>
							</view>
							<view class="other-order-num-item">
								<text class="title">子单号：</text>
								<view class="value">
									<text class="txt">{{item.logistics_child_sn}}</text>
									<image @click.stop="copyData(item.logistics_child_sn)" src="/static/images/copy.png" mode="widthFix" class="img"></image>
								</view>
							</view>
							<view class="other-order-num-item">
								<text class="title">转单号：</text>
								<view class="value">
									<text class="txt">{{item.dispatch_logistics_number}}</text>
									<image @click.stop="copyData(item.dispatch_logistics_number)" src="/static/images/copy.png" mode="widthFix" class="img"></image>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="order-footer">
					<view class="see-image" @click.stop="showImage(item)">查看图片</view>
					<view @click.stop="cargoStatusDetail(item)" class="casgo-status-btn">货态详情</view>
				</view>
			</view>
		</view>
		
		<u-loadmore :status="loadStatus" height="80rpx" />
	</view>
</template>

<script>
	import {
		expressDetail
	} from '@/api/order.js';
	export default {
		data() {
			return {
				type: 'notWarehousing', // notWarehousing 待进仓  warehousing 已进仓  outWarehousing 已出仓,
				page: 1,
				loadStatus: 'loadmore',
				dateRange: [],
				order: '',
				surname: '',
				title: '',
				searchTimeList: [
					{title: '全部', value: ''},
					{title: '昨天', value: 'yestoday'},
					{title: '今天', value: 'today'},
					{title: '最近一周', value: 'last_weekday'},
					{title: '最近一月', value: 'last_monthday'},
				],
				searchTimeSelectIndex: 0,
				list: [],
				logisticsCount: 0,
				sumWeight: 0,
				sumGoodSize: 0
			};
		},
		watch: {
			async order() {
				await this.pullOrderList();
			},
			async surname() {
				await this.pullOrderList();
			},
			async title() {
				await this.pullOrderList();
			},
			async searchTimeSelectIndex() {
				await this.pullOrderList();
			}
		},
		async onLoad(options) {
			if (options.order) {
				this.order = options.order;
			}
			await this.loadData();
		},
		async onPullDownRefresh() {
			await this.pullOrderList();
			uni.stopPullDownRefresh();
		},
		async onReachBottom() {
			await this.loadOrderList();
		},
		methods: {
			cargoStatusDetail(item) {
				uni.setStorageSync('searchlogisticSn', item.logistics_sn || '');
				uni.switchTab({
					url: `/pages/search/index`
				});
			},
			searchTimeChange(index) {
				if (this.searchTimeSelectIndex == index) return;
				this.searchTimeSelectIndex = index;
			},
			copyData(data) {
				uni.setClipboardData({
					data
				});
			},
			async pullOrderList() {
				this.page = 1;
				this.loadStatus = 'loadmore';
				await this.loadOrderList();
			},
			async loadOrderList() {
				try{
					if (this.loadStatus === 'nomore') {
						return;
					}
					this.loadStatus = 'loading';
					let page = this.page;
					if (page == 1) {
						this.list = [];
					}
					let res = await expressDetail({
						p: page, 
						logistics_number: this.order,
						good_quantity: this.title, 
						username: this.surname,
						search_time: this.searchTimeList[this.searchTimeSelectIndex]?.value || ''
					});
					this.loadStatus = 'loadmore';
					
					let list = res.data || [],
						listLength = list.length;
					if (listLength <= 0) {
						this.loadStatus = 'nomore';
					}
					this.list = [...(page === 1 ? [] : this.list), ...list];
					this.page = page + 1;
					this.logisticsCount = res.logistics_count || 0;
					this.sumWeight = res.sum_weight || 0;
					this.sumGoodSize = res.sum_good_size || 0;
				}catch(e){
					this.loadStatus = 'loadmore';
					console.log(e);
				}
			},
			async loadData() {
				await this.loadOrderList();
			},
			showImage(item){
				uni.navigateTo({
					url:`/pages/showImage/show-image?img=${item.good_pic[0]}`
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}
	
	.head-block {
		width: 100%;
		height: 360rpx;

		.head {
			position: fixed;
			z-index: 10;
			left: 0;
			width: inherit;
			height: inherit;
			padding: 20rpx 30rpx;
			box-sizing: border-box;
			background-color: #fff;
			border-radius: 0 0 20rpx 20rpx;
			box-shadow: 2rpx 2rpx 28rpx 0 rgba(0,0,0,0.06);
			
			.order-search {
				width: 100%;
				height: 80rpx;
				border-radius: 80rpx;
				background-color: #f5f5f5;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 30rpx;
				box-sizing: border-box;
				
				.img {
					width: 34rpx;
					height: 34rpx;
				}
				
				.inp,
				.inp-place {
					text-align: left;
					font-size: 26rpx;
					font-weight: 500;
					color: #666;
				}
				
				.inp {
					flex: 1;
					padding-left: 20rpx;
					box-sizing: border-box;
					color: #333;
				}
			}
			
			.search-time {
				width: 100%;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 26rpx;
				color: #666;
				transition: all .5s;
				
				.search-time-item.active {
					font-weight: bold;
					color: #E6201A;
				}
			}
		
			.other-condition {
				width: 100%;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			
				.product-search,
				.addressee-search {
					flex: 1;
					height: 60rpx;
					border-radius: 60rpx;
					display: flex;
					align-items: center;
					justify-content: flex-start;
					padding: 0 30rpx;
					box-sizing: border-box;
					margin-left: 20rpx;
					background-color: #f5f5f5;
					
					.inp,
					.inp-place {
						font-size: 24rpx;
						font-weight: 500;
						color: #999;
						text-align: left;
					}
					
					.inp {
						flex: 1;
						color: #333;
					}
				}
				
				.product-search {
					margin-left: 0;
				}
			}
			
			.summary-info {
				width: 100%;
				height: 80rpx;
				display: flex;
				align-items: center;
				justify-content: space-around;
				
				.summary-item {
					.txt {
						font-size: 26rpx;
						color: #666;
					}
					
					.txt.active {
						color: #E6201A;
					}
				}
			}
		}
	}

	.order-list {
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
		
		.order-item {
			background-color: #fff;
			width: 100%;
			margin-bottom: 20rpx;
			border-radius: 20rpx;
			box-shadow: 2rpx 2rpx 28rpx 0 rgba(0,0,0,0.06);
			
			.ellipsis {
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
			}
			
			.flex {
				display: flex;
				width: 100%;
			}
			
			.flex-space-between {
				justify-content: space-between;
			}
			
			.flex-align-center {
				align-items: center;
			}
			
			.color-09f {
				color: #09f;
			}
			
			.font-24 {
				font-size: 24rpx;
			}
			
			.order-head {
				border-bottom: 1rpx solid #eee;
				box-sizing: border-box;
				padding: 20rpx;
				box-sizing: border-box;
			}
			
			.copy {
				display: flex;
				align-items: center;
				
				.img {
					margin-left: 10rpx;
					width: 20rpx;
					height: 20rpx;
				}
			}
			
			.order-body {
				padding: 20rpx;
				box-sizing: border-box;
				
				.time-order {
					padding-bottom: 20rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					
					.item {
						display: flex;
						align-items: center;
						
						.txt {
							font-size: 24rpx;
							color: #666;
						}
					}
				}
				
				.express-dynamic {
					flex-direction: column;
					align-items: flex-start;
					width: 100%;
					
					.item {
						.txt {
							color: #E6201A;
						}
					}
					.dynamic-txt {
						padding-top: 10rpx;
						width: 100%;
					}
				}
				
				.order-goods {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding-top: 20rpx;
					
					.goods-image-title {
						display: flex;
						align-items: stretch;
						justify-content: center;
						flex-direction: column;
						overflow: hidden;
						
						.image {
							width: 100rpx;
							height: 100rpx;
							border-radius: 16rpx;
							overflow: hidden;
							
							.img {
								width: 100%;
								height: 100%;
							}
						}
						
						.title {
							padding-top: 10px;
							overflow: hidden;
							text-align: center;
							
							.txt {
								overflow: hidden;
								text-align: center;
								text-overflow: ellipsis;
								white-space: nowrap;
								font-size: 28rpx;
								color: #000;
							}
						}
					}
					
					.acting-num {
						display: flex;
						align-items: flex-end;
						justify-content: space-between;
						flex-direction: column;
						flex: 1;
						
						.num-item {
							padding-bottom: 15rpx;
							font-size: 26rpx;
							color: #333;
							font-weight: bold;
							display: flex;
							align-items: center;
							justify-content: flex-start;
							width: 160rpx;
							
							.num-item-title {
								width: 100rpx;
								text-align: justify;
								display: inline-block;
								text-align-last: justify;
							}
							
							.num-item-val {
								flex: 1;
								text-align: right;
							}
						}
						
						.num-item:last-child {
							padding-bottom: 0;
						}
						
						.num-item.active {
							color: #E6201A;
						}
					}
				}
				
				.order-type-pack {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 26rpx;
					color: #E6201A;
					padding: 20rpx 0;
				}
				
				.order-other-info {
					padding: 20rpx;
					border-radius: 16rpx;
					background-color: rgba(0, 0, 0, .05);
					display: flex;
					align-items: center;
					justify-content: space-between;
					
					.other-info-item {
						flex: 1;
						position: relative;
						display: flex;
						align-items: stretch;
						justify-content: space-between;
						flex-direction: column;
						font-size: 22rpx;
						color: #666;
						
						.goods-other-info-line,
						.other-order-num-item {
							margin-bottom: 20rpx;
						}
						
						.goods-other-info-line:last-child,
						.other-order-num-item:last-child {
							margin-bottom: 0;
						}
					}
					
					.other-info-item:first-child {
						margin-right: 10rpx;
						
						&::after {
							content: ' ';
							display: block;
							width: 2rpx;
							height: 80%;
							background-color: #dedede;
							border-radius: 2rpx;
							position: absolute;
							right: -11rpx;
							top: 50%;
							transform: translateY(-50%);
						}
					}
					
					.other-info-item:last-child {
						margin-left: 10rpx;
					}
					
					.goods-other-info-line {
						display: flex;
						align-items: center;
						justify-content: space-between;
						
						.goods-other-info-item {
							flex: 1;
						}
					}
					
					.other-order-num {
						display: flex;
						align-items: flex-start;
						justify-content: space-between;
						flex-direction: column;
						
						.other-order-num-item {
							display: flex;
							align-items: center;
							justify-content: flex-start;
							
							.value {
								display: flex;
								align-items: center;
								justify-content: flex-start;
								
								.img {
									width: 20rpx;
									height: 20rpx;
									margin-left: 5rpx;
								}
							}
						}
					}
				}
			}
		
			.order-footer {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				padding: 0 20rpx 20rpx 0;
				
				.casgo-status-btn {
					font-size: 24rpx;
					color: #E6201A;
					padding: 3rpx 10rpx;
					border: 1rpx solid #E6201A;
					border-radius: 10rpx;
					box-sizing: border-box;
				}
			}
		}
		
		.order-item:last-of-type {
			margin-bottom: 0;
		}
	}
	.see-image{
		width: 150rpx;
		height: 50rpx;
		border-radius: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		font-size: 28rpx;
		background-color: #E6201A;
		margin-right: 20rpx;
	}
</style>
